﻿@using CuongHanh
@{
    ViewBag.Title = "Chất liệu";
    Layout = "~/Views/Shared/_ALayout.cshtml";
}
@section script
{
    <script type="text/javascript">
        function search() {
            window.App.gvData.store.proxy.extraParams.query = window.App.txtSearch.getValue();
            window.App.gvData.store.load();
        }

        function getImage(value, record) {
            var url = '@Url.Content(AppUtil.GEM_IMAGE_PATH)';
            return "<img style='height:40px;' alt='no image' src='" + url + (value?value:"no-image.jpg") + "'/>";
        }
    </script>
}
@(Html.X()
          .Viewport()
          .Layout(LayoutType.Border)
          .Items(view =>
                 {
                     Toolbar topMenu = new Toolbar
                                       {
                                               Region = Region.North
                                       };
                     view.Add(topMenu);
                     topMenu.Add(Html.X()
                             .Label()
                             .Text("Tìm kiếm: "));
                     topMenu.Add(Html.X()
                             .TextField()
                             .ID("txtSearch")
                             .Width(550)
                             .EmptyText("Tìm kiếm theo: Mã, Tên"));
                     topMenu.Add(Html.X()
                             .Button()
                             .Icon(Icon.Find)
                             .Text("Xem")
                             .OnClientClick("search")
                             );
                     topMenu.Add(new ToolbarFill());
                     topMenu.Add(Html.X()
                             .Button()
                             .Text("Thêm mới")
                             .Icon(Icon.Add)
                             .DirectEvents(de =>
                                           {
                                               de.Click.Url = Url.Action("ShowAdd");
                                               de.Click.ExtraParams.Add(new Parameter("containerId",
                                                       "wdModify"));
                                           })
                             );

                     view.Add(Html.X()
                             .GridPanel()
                             .ForceFit(true)
                             .ID("gvData")
                             .View(Html.X()
                                     .GridView()
                                     .EnableTextSelection(true)
                             )
                             .Region(Region.Center)
                             .ColumnModel(column =>
                                          {
                                              column.Add(Html.X()
                                                      .Column()
                                                        .MinWidth(55)
                                                      .MaxWidth(55)
                                                      .DataIndex("Image")
                                                      .Renderer("getImage")
                                                      );
                                              column.Add(Html.X()
                                                      .Column()
                                                      .DataIndex("Code")
                                                      .Text("Mã")
                                                      );
                                              column.Add(Html.X()
                                                      .Column()
                                                      .DataIndex("Name")
                                                      .Text("Tên T.Việt")
                                                      );
                                              column.Add(Html.X()
                                                      .Column()
                                                      .DataIndex("NameEn")
                                                      .Text("Tên T.Anh")
                                                      );
                                              column.Add(Html.X()
                                                      .Column()
                                                      .DataIndex("ParenId")
                                                      .Text("Mẫu Cha")
                                                      );
                                              column.Add(Html.X()
                                                      .Column()
                                                      .DataIndex("StyleTypeId")
                                                      .Text("Loại")
                                                      );
                                              column.Add(Html.X()
                                                      .DateColumn()
                                                      .DataIndex("LastModified")
                                                      .Text("Lần thay đổi cuối")
                                                      .Format(AppUtil.DATE_TIME_FORMAT)
                                                      );

                                              column.Add(Html.X()
                                                      .CommandColumn()
                                                      .MinWidth(450)
                                                      .MaxWidth(450)
                                                      .Commands(v =>
                                                                {
                                                                    v.Add(new GridCommand
                                                                          {
                                                                                  Icon = Icon.TableEdit,
                                                                                  CommandName = "Edit",
                                                                                  Text = "Sửa"
                                                                          });
                                                                    v.Add(new GridCommand
                                                                    {
                                                                        Icon = Icon.TableEdit,
                                                                        CommandName = "Description",
                                                                        Text = "Mô tả"
                                                                    });
                                                                    //v.Add(new GridCommand
                                                                    //{
                                                                    //    Icon = Icon.TableEdit,
                                                                    //    CommandName = "DescriptionEn",
                                                                    //    Text = "Mô tả.TA"
                                                                    //});
                                                                    v.Add(new GridCommand
                                                                          {
                                                                                  Icon = Icon.TableEdit,
                                                                                  CommandName = "Material",
                                                                                  Text = "Chất liệu"
                                                                          });
                                                                    v.Add(new GridCommand
                                                                          {
                                                                                  Icon = Icon.TableEdit,
                                                                                  CommandName = "StyleStone",
                                                                                  Text = "Đá"
                                                                          });
                                                                    v.Add(new GridCommand
                                                                    {
                                                                        Icon = Icon.TableEdit,
                                                                        CommandName = "ParentMaterial",
                                                                        Text = "Mẫu-Chất liệu (Cha)"
                                                                    });
                                                                }
                                                      )
                                                      .DirectEvents(de =>
                                                                    {
                                                                        de.Command.EventMask.ShowMask = true;
                                                                        de.Command.ExtraParams.Add(new Parameter("containerId",
                                                                                "wdModify"));
                                                                        de.Command.ExtraParams.Add(new Parameter("command",
                                                                                "command",
                                                                                ParameterMode.Raw));
                                                                        de.Command.ExtraParams.Add(new Parameter("id",
                                                                                "record.data.Id",
                                                                                ParameterMode.Raw));
                                                                        de.Command.ExtraParams.Add(new Parameter("parentId",
                                                                               "record.data.ParentId",
                                                                               ParameterMode.Raw));
                                                                        de.Command.Url = Url.Action("Command");
                                                                        de.AutoDataBind = true;
                                                                    })
                                                      );
                                              column.Add(Html.X()
                                                      .CommandColumn()
                                                        .MinWidth(65)
                                                      .MaxWidth(65)
                                                      .Commands(v =>
                                                              v.Add(new GridCommand
                                                                    {
                                                                            Icon = Icon.Delete,
                                                                            CommandName = "Delete",
                                                                            Text = "Xóa"
                                                                    })
                                                      )
                                                      .DirectEvents(de =>
                                                                    {
                                                                        de.Command.EventMask.ShowMask = true;
                                                                        de.Command.ExtraParams.Add(new Parameter("containerId",
                                                                                "wdModify"));
                                                                        de.Command.ExtraParams.Add(new Parameter("command",
                                                                                "command",
                                                                                ParameterMode.Raw));
                                                                        de.Command.ExtraParams.Add(new Parameter("id",
                                                                                "record.data.Id",
                                                                                ParameterMode.Raw));
                                                                        de.Command.Url = Url.Action("Command");
                                                                        de.Command.Confirmation.ConfirmRequest = true;
                                                                        de.Command.Confirmation.BeforeConfirm = "config.confirmation.title = 'Thông báo'; config.confirmation.message = 'Bạn có muốn xóa dòng này không?';";
                                                                        de.AutoDataBind = true;
                                                                    })
                                                      );
                                          })
                             .BottomBar(Html.X()
                                     .PagingToolbar())
                             .Store(Html.X()
                                     .Store()
                                     .RemotePaging(true)
                                     .PageSize(30)
                                     .ID("storeGvData")
                                     .AutoLoad(true)
                                     .AutoSync(false)
                                     .Model(c => c.Add(Html.X()
                                             .Model()
                                             .Fields("Id",
                                                     "Code",
                                                     "Name",
                                                     "NameEn",
                                                     "ParentId",
                                                     "Image",
                                                     "StyleTypeId",
                                                     "LastModified"
                                             )
                                             .IDProperty("Id")))
                                     .Proxy(c => c.Add(Html.X()
                                             .AjaxProxy()
                                             .Json(true)
                                             .Url(Url.Action("GetDatas"))
                                             .ActionMethods(v => v.Read = HttpMethod.POST)
                                             .Reader(Html.X()
                                                     .JsonReader()
                                                     .Root("data")
                                                     .TotalProperty("total"))
                                             .ExtraParams(param => param.Add(new Parameter("query",
                                                     "",
                                                     ParameterMode.Value)))
                                             ))
                                     .AutoLoadParams(c =>
                                                     {
                                                         c.Add(new Parameter("start",
                                                                 "0",
                                                                 ParameterMode.Raw));
                                                         c.Add(new Parameter("limit",
                                                                 "30",
                                                                 ParameterMode.Raw));
                                                     }))
                             );
                 }))


@(Html.X()
          .Window()
          .ID("wdModify")
          .Hidden(true)
          .Modal(true)
          .Resizable(false)
          .Title("Thông tin chất liệu")
          .Width(550)
          .Height(280)
          .Constrain(true)
          .StyleHtmlCls("background-color:white;")
          )